import {PropTypes} from 'react';
import {compose, withContext} from 'recompose';
import {message} from 'antd';
import {getUser} from '../login';
import redux from './_/redux';

message.config({
    duration: 3
});

/**
 * 定义全局配置
 * @type {{title: string, width: undefined, height: undefined}}
 */
export const app = {
    title: '眼科电子病历',
    maxWidthModal: 1000 //
};

export default compose(
    withContext({
        location: PropTypes.object,
        params: PropTypes.object,
        routes: PropTypes.array,
        app: PropTypes.object
    }, props => ({
        location: props.location,
        params: props.params,
        routes: props.routes,
        app
    })),
    redux('app', {
        data: 'user',
        actions: 'relogin'
    })
)(props => {
    let {data: user} = props;
    if (!user) {
        user = getUser();
        if (user) {
            setTimeout(() => {
                // 更新redux store
                props.relogin(user);
            }, 0);
        }
    }
    return props.children;
});

